package com.lv.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lv.entity.Student;
import com.lv.entity.StudentREQ;
import com.lv.mapper.StudentMapper;
import com.lv.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 我的代码-www.lv.com
 * @since 2021-06-30
 */
@RestController
@RequestMapping("/student")
@CrossOrigin
public class StudentController {

    //@Autowired
    @Resource
    private StudentServiceImpl studentService;


    @RequestMapping("/number")
    public List<Student> findStudentScore(){
        return studentService.findStudentScore();
    }

    @GetMapping("/list")
    public List<Student> findAll(){
        return studentService.findAll();
    }

    @GetMapping("/byname")   //演示${}和#{}的区别
    public Student byname(String name,String gender){
        return studentService.byname(name,gender);
    }

    @PostMapping("/ids")    //根据多条ID查询
    public List<Student> findByIds(@RequestParam("ids") List<Integer> ids){
        return studentService.findByIds(ids);
    }


    @PostMapping("/fenye")
    public Page<Student> fenye(@RequestBody StudentREQ studentREQ){
        return studentService.fenye(studentREQ);
    }

    @PutMapping
    public Boolean update(@RequestBody Student student){
        return studentService.updateById(student);
    }


    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable("id") Integer id){
        return studentService.removeById(id);
    }

    @PostMapping("/add")
    public Boolean add(@RequestBody Student student){
        return studentService.save(student);
    }

    @GetMapping("/{id}")
    public Student getById(@PathVariable("id") Integer id){
        return studentService.getById(id);
    }
}
